package com.zoe.config;

import com.zoe.bean.Color;
import com.zoe.bean.Color1;
import com.zoe.bean.ColorFac;
import com.zoe.bean.Person;
import com.zoe.condition.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @Author Zoe
 * @Date: 2020/11/06
 * @Description
 */
@Configuration
@Import({Color.class, Color1.class,MainConfig.class, MyImportSelect.class, MyImportBeanDefinitionRegistrar.class})
public class MainConfig2 {
    /**
     *     String SCOPE_SINGLETON = "singleton"; 单例   容器创建时即加载组件
     *     String SCOPE_PROTOTYPE = "prototype"; 多例  容器创建时组件不加载，调用时再加载
     * @return
     */
//    @Scope("singleton")
    @Bean("bill")
    @Conditional({WindowsCondition.class})
    public Person person() {
        System.out.println("window");
        return new Person(12,"张三");
    }

    /**
     * 懒加载，容器加载时组价不加载，调用时再加载
     * @return
     */
//    @Lazy //懒加载
    @Bean("linux")
    @Conditional({LinuxCondition.class})
    public Person person1(){
        System.out.println("Linux");
        return new Person(13,"李四");
    }
    @Bean
    public ColorFactoryBean colorFactoryBean(){
        return new ColorFactoryBean();
    }
}
